home *** CD-ROM | disk | FTP | other *** search
- package java.net;
-
- import java.io.IOException;
- import java.io.InvalidObjectException;
- import java.io.ObjectInputStream;
-
- public class InetSocketAddress extends SocketAddress {
- private String hostname;
- private InetAddress addr;
- private int port;
- private static final long serialVersionUID = 5076001401234631237L;
-
- private InetSocketAddress() {
- this.hostname = null;
- this.addr = null;
- }
-
- public InetSocketAddress(int var1) {
- this(InetAddress.anyLocalAddress(), var1);
- }
-
- public InetSocketAddress(InetAddress var1, int var2) {
- this.hostname = null;
- this.addr = null;
- if (var2 >= 0 && var2 <= 65535) {
- this.port = var2;
- if (var1 == null) {
- this.addr = InetAddress.anyLocalAddress();
- } else {
- this.addr = var1;
- }
-
- } else {
- throw new IllegalArgumentException("port out of range:" + var2);
- }
- }
-
- public InetSocketAddress(String var1, int var2) {
- this.hostname = null;
- this.addr = null;
- if (var2 >= 0 && var2 <= 65535) {
- if (var1 == null) {
- throw new IllegalArgumentException("hostname can't be null");
- } else {
- try {
- this.addr = InetAddress.getByName(var1);
- } catch (UnknownHostException var4) {
- this.hostname = var1;
- this.addr = null;
- }
-
- this.port = var2;
- }
- } else {
- throw new IllegalArgumentException("port out of range:" + var2);
- }
- }
-
- public static InetSocketAddress createUnresolved(String var0, int var1) {
- if (var1 >= 0 && var1 <= 65535) {
- if (var0 == null) {
- throw new IllegalArgumentException("hostname can't be null");
- } else {
- InetSocketAddress var2 = new InetSocketAddress();
- var2.port = var1;
- var2.hostname = var0;
- var2.addr = null;
- return var2;
- }
- } else {
- throw new IllegalArgumentException("port out of range:" + var1);
- }
- }
-
- private void readObject(ObjectInputStream var1) throws IOException, ClassNotFoundException {
- var1.defaultReadObject();
- if (this.port >= 0 && this.port <= 65535) {
- if (this.hostname == null && this.addr == null) {
- throw new InvalidObjectException("hostname and addr can't both be null");
- }
- } else {
- throw new InvalidObjectException("port out of range:" + this.port);
- }
- }
-
- public final int getPort() {
- return this.port;
- }
-
- public final InetAddress getAddress() {
- return this.addr;
- }
-
- public final String getHostName() {
- if (this.hostname != null) {
- return this.hostname;
- } else {
- return this.addr != null ? this.addr.getHostName() : null;
- }
- }
-
- final String getHostString() {
- if (this.hostname != null) {
- return this.hostname;
- } else if (this.addr != null) {
- return this.addr.hostName != null ? this.addr.hostName : this.addr.getHostAddress();
- } else {
- return null;
- }
- }
-
- public final boolean isUnresolved() {
- return this.addr == null;
- }
-
- public String toString() {
- return this.isUnresolved() ? this.hostname + ":" + this.port : this.addr.toString() + ":" + this.port;
- }
-
- public final boolean equals(Object var1) {
- if (var1 != null && var1 instanceof InetSocketAddress) {
- InetSocketAddress var2 = (InetSocketAddress)var1;
- boolean var3 = false;
- if (this.addr != null) {
- var3 = this.addr.equals(var2.addr);
- } else if (this.hostname != null) {
- var3 = var2.addr == null && this.hostname.equals(var2.hostname);
- } else {
- var3 = var2.addr == null && var2.hostname == null;
- }
-
- return var3 && this.port == var2.port;
- } else {
- return false;
- }
- }
-
- public final int hashCode() {
- if (this.addr != null) {
- return this.addr.hashCode() + this.port;
- } else {
- return this.hostname != null ? this.hostname.hashCode() + this.port : this.port;
- }
- }
- }
-